package net.qhzw.vip.qiyu.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.qhzw.vip.qiyu.entity.DtsCarRental;
import net.qhzw.vip.qiyu.model.SysCarRentalQuery;
import net.qhzw.vip.qiyu.result.JsonResult;
import net.qhzw.vip.qiyu.service.DtsCarRentalService;
import net.qhzw.vip.qiyu.service.MemberWalletService;
import net.qhzw.vip.qiyu.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.Map;

@RestController
@RequestMapping("sys/carRentalDetaile")
@Api(tags = "在租明细")
public class SysCarRentalDetaileController {

    @Autowired
    private DtsCarRentalService dtsCarRentalService;

    @Autowired
    private MemberWalletService memberWalletService;

    @ApiOperation(value = "分页查询在租明细")
    @GetMapping
    public JsonResult findByPage(Page<DtsCarRental> page, SysCarRentalQuery query) {
        Long shopId = SecurityUtils.getLoginUser().getShopId();
        Map<String, Object> result = dtsCarRentalService.carRentalDetails(page, shopId, query);
        return JsonResult.ok(result);
    }

    @ApiOperation(value = "导出台账")
    @PostMapping("exportLedger")
    public void exportLedger(HttpServletResponse response, @RequestBody(required = false) SysCarRentalQuery query) {
        Long shopId = SecurityUtils.getLoginUser().getShopId();
        dtsCarRentalService.exportLedger(response, shopId, query);
    }

    @ApiOperation(value = "修改押金")
    @PostMapping("systemRecharge1")
    public JsonResult systemRecharge1(@RequestBody Map<String, String> param) {
        Long id = Long.valueOf(param.get("id"));
        BigDecimal amount = new BigDecimal(param.get("amount"));
        boolean isOK = memberWalletService.systemRecharge1(id, amount);
        if (isOK) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }


}
